package com.cloudsigns.factorymanager2.project.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.MainActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.activity.ProductStatusTableActivity;

import java.util.List;

/**
 * Created by tony on 2017/12/19.
 */

public class TableLeftAdapter extends BaseAdapter {
    private Context context;
    private List<String> mListData;
    private String tag = "";

    public TableLeftAdapter(Context context, String tag, List<String> mListData) {
        this.context = context;
        this.mListData = mListData;
        this.tag = tag;
    }

    @Override
    public int getCount() {
        return mListData.size();
    }

    @Override
    public Object getItem(int position) {
        return mListData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_table_left_list, null);
            holder.tv_left = (TextView) convertView.findViewById(R.id.tv_left);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (tag.equals("EngineeringInstallationScheduleTableActivity")) {
            holder.tv_left.setText("项目名称/工程名称");
        } else if (tag.equals("ProductionScheduleActivity")) {
            holder.tv_left.setText("平面灯箱");
            holder.tv_left.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent mIntent = new Intent(context, ProductStatusTableActivity.class);
                    context.startActivity(mIntent);
                }
            });
        } else if (tag.equals("ProductStatusTableActivity")) {
            holder.tv_left.setText("吸塑");
        } else {
            holder.tv_left.setText("工序");
        }


        return convertView;
    }

    class ViewHolder {
        TextView tv_left;
    }
}
